package ezeye.decoder;

//import com.video.h264.VideoFrameInfor;

public class StageFrightDecoder {
    private long mDecoderContext = 0L;
    private DecodeInfo mInfo = null;

    static {
        System.loadLibrary("stagefrightdecoder");
    }
    
    public class DecodeInfo {
        public int mSize;
        public int mWidth;
        public int mHeight;
    }

    public StageFrightDecoder(int width, int height) {
        try {
            long l = Initialize(width, height);
            mDecoderContext = l;
            mInfo = new DecodeInfo();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void Cleanup() {
        if (0 != mDecoderContext) {
            Destroy(mDecoderContext);
            mDecoderContext = 0;
        }
        
        mInfo = null;
    }

    private native long Initialize(int width, int height);
    private native void Destroy(long context);
    private native int DecodeFrame(long context, boolean isKey, byte[] src, int srcPos, int srcLen, byte[] dst, int dstPos, int dstLen, DecodeInfo info);
    private native int getWidth();
    public DecodeInfo DecodeOneFrame(boolean isKey, byte[] src, int srcPos, int srcLen, byte[] dst, int dstPos, int dstLen) {
        mInfo.mSize = 0;
        mInfo.mWidth = 0;
        mInfo.mHeight = 0;
        int ret = DecodeFrame(mDecoderContext, isKey, src, srcPos, srcLen, dst, dstPos, dstLen, mInfo);
        return mInfo;
    }
}
